This is genuinely hideous
Max distance is an absolutely accursed metric XD